<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="icon" href="">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/nprogress/nprogress.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/fonts/font-awesome/font-awesome.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/icheck/icheck.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/animate/animate.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.css?v=1.1" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/common/common_20170925.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/inside/inside.css?v=1" rel="stylesheet">

</head>

<body class="white-bg">
<div class="wrapper wrapper-content ibox float-e-margins">
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-sm-12" >
                    <table id="cpTableEvents" data-toggle="table" data-mobile-responsive="true" class="table table-bordered table-strip table-hovered">
                        <thead>
                        <tr>
                            <th data-field="title" data-formatter="titleFormatter">文档标题</th>
                            <th data-field="add_person">添加人</th>
                            <th data-field="createDate">添加日期</th>
                            <th data-field="head" data-formatter="checkedFormatter">是否关联</th>
                            <th data-field="head" data-formatter="copyFormatter">复制接口地址</th>

                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://static.9hive.cn/global/vendor/jquery/jquery-2.1.4.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/nprogress/nprogress.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/jquery.validate.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/additional-methods.min.js"></script>

<script src="https://static.9hive.cn/global/vendor/jquery-validate/localization/messages_zh.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-ajaxform/ajax-form.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/layer/layer.js"></script>

<script>

    function titleFormatter(value, row, index){
        var html = '<a href="/programmer/file/detail?id='+row.id+'" title="查看详情" style="font-size:15px" target="_blank">'+row.title+'</a>';
        return html;
    }
    function checkedFormatter(value, row, index) {
        var html='';
        if(row.status=='true'){
            html += '<input class="ischecked"  name="checked" id="'+row.id+'" type="checkbox" checked />';
        }else{
            html += '<input class="ischecked"  name="checked" id="'+row.id+'" type="checkbox" />';
        }
        return html;
    }

    function copyFormatter(value, row, inde) {
        var html='';
        html += '<a href="javascript:void(0)" onclick="copyToClipboard(\''+row.url+'\'+\'/\'+\''+row.id+'\');"><span style="margin-left:10px;font-size: 15px" class="fa fa-share-alt" data-toggle="tooltip" title="复制接口地址"></span></a>';
        html += '<textarea id=\''+row.url+'/'+row.id+'\' style="display: none;" value=\''+row.url+'/'+row.id+'\'>'+row.url+'/'+row.id+'</textarea>';
        return html;

    }

    function copyToClipboard(elementId) {
        // 创建元素用于复制
        var aux = document.createElement("input");

        // 获取复制内容
        var content = document.getElementById(elementId).innerHTML || document.getElementById(elementId).value;

        // 设置元素内容
        aux.setAttribute("value", content);

        // 将元素插入页面进行调用
        document.body.appendChild(aux);

        // 复制内容
        aux.select();

        // 将内容复制到剪贴板
        document.execCommand("copy");

        // 删除创建元素
        document.body.removeChild(aux);
        parent.layer.msg("复制成功!")
    }



    $(document).on("click",".ischecked",function () {
        if($(this).is(':checked')){
            $(this).attr("value",'1');//选中
        }else{
            $(this).attr("value",'0');//非选中
        }
        var ischecked=$(this).attr("value");//1.选中,0非选中
        var file_instructions_id_relation=$(this).attr("id");//接口id

        if(ischecked=='1'){
            $.ajax({
                url: "/programmer/filerelation/save",
                type: 'GET',
                data:{
                    "file_instructions_id":"${file_instructions_id!}",
                    "file_instructions_id_relation":file_instructions_id_relation

                },
                success: function(data){
                    if (data.state=="ok" == false){
                        layer.msg(data.info);
                    }
                }});
        }else if(ischecked=='0'){
            $.ajax({
                url: "/programmer/filerelation/delete",
                type: 'GET',
                data:{
                    "file_instructions_id":"${file_instructions_id!}",
                    "file_instructions_id_relation":file_instructions_id_relation

                },
                success: function(data){
                    if (data.state=="ok" == false){
                        layer.msg(data.info);
                    }
                }});
        }


    });





    (function() {
        $('#cpTableEvents').bootstrapTable({
            url: "ajaxlist?file_instructions_id=${file_instructions_id!}",
            search: true,
            pagination: true,
            showRefresh: true,
            showToggle: true,
            showColumns: true,
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            icons: {
                refresh: 'glyphicon-repeat',
                toggle: 'glyphicon-list-alt',
                columns: 'glyphicon-list'
            }
        });
    })();
</script>
</body>

</html>
